package com.zzlzd.drp.domain;


import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.persistence.*;
import java.util.Date;
import java.util.List;
import java.util.Map;

public interface MoneyLogRep extends JpaRepository<MoneyLogDto,Integer> {


    /***
     * 收益统计
     * @param id
     * @return
     */
    @Query(nativeQuery=true, value=" SELECT * FROM (select SUM(money) dangri from money_log where to_days(creat_time) = to_days(now()) AND user_id = ?1 AND type = 3) a,(SELECT SUM(money) benyue FROM money_log WHERE DATE_FORMAT(creat_time, '%Y%m') = DATE_FORMAT(CURDATE() ,'%Y%m') AND user_id = ?1 AND type = 3)b,(SELECT SUM(money) leiji FROM money_log WHERE user_id = ?1 AND type = 3)c ")
    public Map<String, Object> findShouYi(Integer id);

    @Query(nativeQuery=true, value=" SELECT * FROM money_log WHERE user_id =0 AND type = 2 order by id DESC")
    public List<MoneyLogDto> findLog();

    @Query(nativeQuery=true, value=" SELECT * FROM money_log WHERE user_id =0 AND type = 4 order by id DESC")
    public List<MoneyLogDto> findSyLog();
}
